@extends('backstage.layout.master')
@section('title', '添加产品')
@section('style')
    <style>
        a{
            cursor: pointer;
        }
        .search-tool{
            margin-bottom: 20px;
        }
    </style>
@stop
@section('content')
    <div class="breadcrumbs" id="breadcrumbs">
        <script type="text/javascript">
            try {
                ace.settings.check('breadcrumbs', 'fixed')
            } catch (e) {
            }
        </script>

        <ul class="breadcrumb">
            <li>
                <i class="icon-home home-icon"></i>
                <a href="backstage/home">主页</a>
            </li>

            <li class="active">
                <a href="backstage/module/module-list">模块管理</a>
            </li>
            <li>
                添加产品
            </li>
        </ul><!-- .breadcrumb -->
    </div>

    <div class="page-content">
        <div class="page-header">
            <h1>
                添加产品
            </h1>
        </div>
        <div class="row">
            <div class="col-sm-12 search-tool">
                <div class="well">
                    <select name="product_temp_category_id" id="product-temp-category" @if($redirect_module != 0) disabled @endif>
                        @foreach($product_temp_categorys as $product_temp_category)
                            <option @if($product_temp_category->product_temp_category_id == $redirect_module || ((isset($conditions->product_temp_category_id) && $conditions->product_temp_category_id == $product_temp_category->product_temp_category_id))) selected @endif value="{{$product_temp_category->product_temp_category_id}}">{{$product_temp_category->name}}</option>
                        @endforeach
                    </select>
                    <select name="user_type" id="user_type">
                        <option value="0" @if(isset($conditions->user_type) && $conditions->user_type == '0') selected @endif>全部</option>
                        <option value="1" @if(isset($conditions->user_type) && $conditions->user_type  == '1') selected @endif>设计师</option>
                        <option value="2" @if(isset($conditions->user_type) && $conditions->user_type  == '2') selected @endif>品牌商</option>
                    </select>
                    <select name="brand_id" id="brand_id">
                        <option value="0" @if(isset($conditions->brand_id) && $conditions->brand_id == '0') selected @endif>全部</option>
                        @foreach($brands as $brand)
                            <option value="{{$brand->brand_id}}" @if(isset($conditions->brand_id) && $conditions->brand_id == $brand->brand_id) selected @endif>{{$brand->brand_name}}</option>
                        @endforeach
                    </select>
                    <select name="is_shelves" id="is_shelves">
                        <option value="-1" @if(isset($conditions->is_shelves) && $conditions->is_shelves  == '-1') selected @endif>全部</option>
                        <option value="1" @if(isset($conditions->is_shelves) && $conditions->is_shelves  == '1') selected @endif>上架</option>
                        <option value="0" @if(isset($conditions->is_shelves) && $conditions->is_shelves  == '0') selected @endif>下架</option>
                    </select>
                    <input type="text" class="keyword1" name="user_param" placeholder="用户昵称/手机号" value="{{isset($conditions->user_param) ? $conditions->user_param : ''}}">
                    <input type="text" class="keyword" name="product_id" placeholder="产品ID" value="{{isset($conditions->product_id) ? $conditions->product_id : ''}}">
                    <input type="button" value=" 搜索 " class="button_search">
                </div>
            </div>
            <div class="col-xs-12">
                <!-- PAGE CONTENT BEGINS -->
                <form class="form-horizontal" role="form" action="backstage/module/add-data" method="post" enctype="multipart/form-data">
                    <input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">
                    <input type="hidden" name="find_module_id" value="{{$find_module_id}}">
                    <div class="table-responsive">
                        <table id="sample-table-1" class="table table-striped table-bordered table-hover">
                            <thead>
                            <tr>
                                <th class="center">
                                    <label>
                                        <input type="checkbox" class="ace">
                                        <span class="lbl"></span>
                                    </label>
                                </th>
                                <th>产品编号</th>
                                <th>产品预览图</th>
                            </tr>
                            </thead>

                            <tbody>
                            @foreach($products as $product)
                                <tr>
                                    <td class="center">
                                        <label>
                                            <input type="checkbox" class="ace" name="data_ids[]" value="{{$product->product_id}}">
                                            <span class="lbl"></span>
                                        </label>
                                    </td>
                                    <td>{{$product->product_id}}</td>
                                    <td>
                                        <img src="{{$product->thumbnail_image}}" style="width: 120px;"/>
                                    </td>
                                </tr>
                            @endforeach
                            </tbody>
                        </table>
                        <div class="row">
                            <div>
                                <div class="dataTables_paginate paging_bootstrap">
                                    @if(empty($conditions))
                                        <?php echo $products->render(); ?>
                                        @else
                                        <?php echo $products->appends(['conditions' => json_encode($conditions)])->render(); ?>
                                    @endif

                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="clearfix form-actions">
                        <div class="col-md-offset-5 col-md-7">
                            <button class="btn btn-info" type="submit">
                                <i class="icon-ok bigger-110"></i>
                                添加
                            </button>
                        </div>
                    </div>
                </form>
                <!-- PAGE CONTENT ENDS -->
            </div><!-- /.col -->
        </div><!-- /.row -->
    </div><!-- /.page-content -->
@stop
@section('script')
    <script type="text/javascript">
        var _token = '{{csrf_token()}}';
        $(function(){
            $(".button_search").click(function(){
                var user_type = $("#user_type option:selected").val();
                var brand_id = $("#brand_id option:selected").val();
                var is_shelves = $("#is_shelves option:selected").val();
                var user_param = $(".keyword1").val();
                var product_id = $(".keyword").val();
                var product_temp_category_id = $("#product-temp-category option:selected").val();
                search(user_type,brand_id,is_shelves,user_param,product_id,product_temp_category_id)
            });
        });
        function search(user_type,brand_id,is_shelves,user_param,product_id,product_temp_category_id){
            var json = '{ "user_type" : "'+ user_type +'", "brand_id" : "'+ brand_id +'", "is_shelves" : "'+is_shelves+'", "user_param" : "'+ user_param +'", "product_id" : "'+product_id+'", "product_temp_category_id" : "'+ product_temp_category_id +'"}';
            console.log(json);
            window.location.href = "backstage/module/add-data/"+'{{$find_module_id}}'+"?conditions="+json;
        }
    </script>
@stop